#define _CRT_SECURE_NO_WARNINGS 1

struct ListNode* detectCycle(struct ListNode* head) {
    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while (fast && fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
        if (fast == slow)
            break;
    }
    if ((fast == NULL) || (fast->next == NULL))
        return NULL;
    struct ListNode* meet = slow;
    struct ListNode* pcur = head;
    while (pcur != meet)
    {
        pcur = pcur->next;
        meet = meet->next;
    }
    return pcur;
}